package com.decent.ejfadmin.order.dao.provider;

import com.decent.ejfadmin.common.bean.ExkSupplyCard;
import com.decent.ejfadmin.common.bean.MagicConsts;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;

/**
 * describe:订单sql管理
 *
 * @author 王元鑫
 * @date 2019/09/07
 */
@SuppressWarnings("StringBufferMayBeStringBuilder")
public class OrderDaoProvider {
    /**
     * 更新销卡订单
     *
     * @param param 参数
     * @return sql
     */
    @SuppressWarnings("unused")
    public String modifySupplyOrder(HashMap<String, Object> param) {
        StringBuffer sql = new StringBuffer(100);
        sql.append("update yuhuang_supply_card set status = #{status} ,settlePrice = ifnull(#{settlePrice},0)" +
                " ,endTime = now() , failReason = ifnull(#{failReason},'') , " +
                "userPrice = #{userPrice},judgeFace = #{judgeFace} where orderId = #{orderId} ");
        String dbStatus = "dbStatus";
        if (param.get(dbStatus) != null) {
            sql.append(" and status in (0,3,4,5,6,7,8) ");
        } else {
            Integer status = (Integer) param.get(MagicConsts.RPC_PARAM_STATUS);
            if (status.equals(1)) {
                sql.append(" and status in (0,2,3,8) ");
            } else {
                sql.append(" and status in (0,3,5,6,7,8) ");
            }
        }
        return sql.toString();
    }

    public String modifyExkSupplyOrder(HashMap<String, ExkSupplyCard> param) {
        StringBuffer sql = new StringBuffer(50);
        sql.append("update yuhuang_supply_card set " +
                "  endTime = #{exkCard.endTime} ");
        ExkSupplyCard exkSupplyCard = param.get("exkCard");
        if (StringUtils.isNotBlank(exkSupplyCard.getAgentNo())) {
            sql.append(" ,agentNo= #{exkCard.agentNo} ");
        }
        if (StringUtils.isNotBlank(exkSupplyCard.getMobileNo())) {
            sql.append(",mobileNo=#{exkCard.mobileNo}  ");
        }
        if (exkSupplyCard.getCost() != null) {
            sql.append(",cost=#{exkCard.cost}");
        }
        if (exkSupplyCard.getJudgeFace() != null) {
            sql.append(",judgeFace=#{exkCard.judgeFace} ");
        }
        sql.append("  where orderId = #{exkCard.orderId} ");
        return sql.toString();
    }
}
